package com.ruoyi.mentor.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mentor.bo.StudentDetailAddBo;
import com.ruoyi.mentor.bo.StudentDetailEditBo;
import com.ruoyi.mentor.bo.StudentDetailQueryBo;
import com.ruoyi.mentor.service.IStudentDetailService;
import com.ruoyi.mentor.vo.StudentDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 研究生详细信息Controller
 *
 * @author LH
 * @date 2021-05-21
 */
@Api(value = "研究生详细信息控制器", tags = {"研究生详细信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mentor/detail")
public class StudentDetailController extends BaseController {

    private final IStudentDetailService iStudentDetailService;

    /**
     * 查询研究生详细信息列表
     */
    @ApiOperation("查询研究生详细信息列表")
    @PreAuthorize("@ss.hasPermi('mentor:detail:list')")
    @GetMapping("/list")
    public TableDataInfo<StudentDetailVo> list(@Validated StudentDetailQueryBo bo) {
        return iStudentDetailService.queryPageList(bo);
    }

    /**
     * 导出研究生详细信息列表
     */
    @ApiOperation("导出研究生详细信息列表")
    @PreAuthorize("@ss.hasPermi('mentor:detail:export')")
    @Log(title = "研究生详细信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(@Validated StudentDetailQueryBo bo) {
        List<StudentDetailVo> list = iStudentDetailService.queryList(bo);
        ExcelUtil<StudentDetailVo> util = new ExcelUtil<StudentDetailVo>(StudentDetailVo.class);
        return util.exportExcel(list, "研究生详细信息");
    }

    /**
     * 获取研究生详细信息详细信息
     */
    @ApiOperation("获取研究生详细信息详细信息")
    @PreAuthorize("@ss.hasPermi('mentor:detail:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iStudentDetailService.queryById(id));
    }

    /**
     * 新增研究生详细信息
     */
    @ApiOperation("新增研究生详细信息")
    @PreAuthorize("@ss.hasPermi('mentor:detail:add')")
    @Log(title = "研究生详细信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@Validated @RequestBody StudentDetailAddBo bo) {
        return toAjax(iStudentDetailService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改研究生详细信息
     */
    @ApiOperation("修改研究生详细信息")
    @PreAuthorize("@ss.hasPermi('mentor:detail:edit')")
    @Log(title = "研究生详细信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult edit(@Validated @RequestBody StudentDetailEditBo bo) {
        return toAjax(iStudentDetailService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除研究生详细信息
     */
    @ApiOperation("删除研究生详细信息")
    @PreAuthorize("@ss.hasPermi('mentor:detail:remove')")
    @Log(title = "研究生详细信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iStudentDetailService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
